import json
import os
import random

import requests
from constants import HEADERS, URL


def get_link(page, page_size, language, desc, keyword):
    random_int = random.randint(0, 2)
    response = requests.get(url=URL, headers=HEADERS, params={
        'q': f'language:{language} {keyword[random_int]}',
        'page': page,
        'per_page': page_size,
        'sort': 'start',
        'order': 'desc'
    })

    response = json.loads(response.text)['items']

    link_list = [f'{item["html_url"]}/archive/refs/heads/master.zip' for item in response]

    return link_list



